﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;

namespace Nova_DAL
{
    public class ABC_Class
    {
        string strSQL = "";
        DbHelper dbHelper = new DbHelper();
        DataSet ds = new DataSet();
        DbCommand cmd = null;

        /// <summary>
        /// 修改ABC百分比
        /// </summary>
        /// <param name="strLane">巷道号</param>
        /// <param name="fA"></param>
        /// <param name="fB"></param>
        /// <param name="fC"></param>
        /// <returns></returns>
        /// Writer：[夏鑫]
        /// Create Date： [2010-7-06]
        public string UpdateSysoption(string strLane, float fA, float fB, float fC)
        {
            string strErrMsg = "";
            try
            {
                strSQL = @"execute [SP_Update_ABC_Detail] @Lane,@A ,@B,@C,@Res output,@ErrMsg output";
                cmd = dbHelper.GetSqlStringCommond(strSQL);
                dbHelper.AddInParameter(cmd, "@Lane", DbType.String, strLane);
                dbHelper.AddInParameter(cmd, "@A", DbType.Double, Convert.ToDouble(fA));
                dbHelper.AddInParameter(cmd, "@B", DbType.Double, Convert.ToDouble(fB));
                dbHelper.AddInParameter(cmd, "@C", DbType.Double, Convert.ToDouble(fC));
                dbHelper.AddOutParameter(cmd, "@Res", DbType.String, 10);
                dbHelper.AddOutParameter(cmd, "@ErrMsg", DbType.String, 1000);
                dbHelper.ExecuteNonQuery(cmd);

                strErrMsg = dbHelper.GetParameter(cmd, "@ErrMsg").Value.ToString();

            }
            catch (Exception ex)
            {
                Console.Write(ex.ToString());
            }
            return strErrMsg;
        }

        /// <summary>
        /// ABC百分比列表
        /// </summary>
        /// <param name="strLane"></param>
        /// <returns></returns>
        /// Writer：[夏鑫]
        /// Create Date： [2010-7-06]
        public DataSet ListSysoption(string strLane)
        {
            try
            {
                strSQL = @"execute [Sp_ABCPosition] @Lane";
                cmd = dbHelper.GetSqlStringCommond(strSQL);
                dbHelper.AddInParameter(cmd, "@Lane", DbType.String, strLane);
                ds = dbHelper.ExecuteDataSet(cmd);
            }
            catch (Exception ex)
            {
                Console.Write(ex.ToString());
            }
            return ds;
        }

        /// <summary>
        /// ABC百分比
        /// </summary>
        /// <param name="strLane">巷道号</param>
        /// <param name="strKind">ABC分类：A:1,B:2,C:3</param>
        /// <returns></returns>
        /// Writer：[夏鑫]
        /// Create Date： [2010-7-06]
        public int CountSysoption(string strLane, string strKind)
        {
            int iCount = 0;
            try
            {
                strSQL = "select count(ABC_Kind) as ABC_Kind from TBase_Position where ABC_Kind='" + strKind + "' and No_Lane='" + strLane + "'";
                cmd = dbHelper.GetSqlStringCommond(strSQL);
                ds = dbHelper.ExecuteDataSet(cmd);
                iCount = Convert.ToInt32(ds.Tables[0].Rows[0]["ABC_Kind"].ToString());
            }
            catch (Exception ex)
            {
                Console.Write(ex.ToString());
            }
            return iCount;
        }

        /// <summary>
        /// 获得总的货位号
        /// </summary>
        /// <param name="strLane">巷道号</param>
        /// <returns></returns>
        /// Writer：[夏鑫]
        /// Create Date： [2010-9-10]
        public int CountPosID(string strLane)
        {
            int iCount = 0;
            try
            {
                strSQL = "select count(pos_id) as pos_id from TBase_Position where No_Lane='" + strLane + "'";
                cmd = dbHelper.GetSqlStringCommond(strSQL);
                ds = dbHelper.ExecuteDataSet(cmd);
                iCount = Convert.ToInt32(ds.Tables[0].Rows[0]["pos_id"].ToString());
            }
            catch (Exception ex)
            {
                Console.Write(ex.ToString());
            }
            return iCount;
        }

        /// <summary>
        /// ABC颜色
        /// </summary>
        /// <param name="strValuechar">ABC分类</param>
        /// <returns></returns>
        /// Writer：[夏鑫]
        /// Create Date： [2010-7-08]
        public string BackColorSysoption(string strValuechar)
        {
            string strBackColor = "";
            try
            {
                strSQL = "select Valuefloat from TSysoption where DisOne='107' and Valuechar='" + strValuechar + "'";
                cmd = dbHelper.GetSqlStringCommond(strSQL);
                ds = dbHelper.ExecuteDataSet(cmd);
                strBackColor = ds.Tables[0].Rows[0]["Valuefloat"].ToString();
            }
            catch (Exception ex)
            {
                Console.Write(ex.ToString());
            }
            return strBackColor;
        }
    }
}
